#ifndef hwboard_H
#define hwboard_H
#include <boardbase.h>
#include <core_debug.h>
// #include "flashFs.h"
extern const char *hwModel;
extern const char *swName;

#define LED_RUN PF15
#define LED_ERR PG8
#define LED_ETH PG7
#define XX_MAX 16
#define YY_MAX 24
#define XA_MAX 10
#define XT_MAX 4
#define YA_MAX 2
typedef struct
{
    u32 enable; //0x55aa55aa有效
    u32 crc;
    u32 len;
} bootloader_t;

#define RTE_IN_FLASH 4096 * 3500
class hwboard : public boardBase
{
public:
    hwboard();
    void beep(bool onoff);

    u8 xx[3], yy[3],xp[3];
    unsigned short xa[10], ya[8],yp[20];
    float xt[10];
    uint8_t alarm, enUSBHost, ipSet;
    uint16_t year, wyear, wdg_time;
    uint8_t month, day, hour, minute, second, week, wdg_en, reboot, rtc_write, status, toInit;
    uint8_t wmonth, wday, whour, wminute, wsecond;
    set_ip_t ipcfg;
    int atemp_init, atemp, avref;
    unsigned int mem_remain;
    void baseinit();
    void netInit();
    void begin();
    void io_init();
    void board_input();
    void board_output();
    void rtc_setup();
    void rtc_get();
    void ioled();
    void flashClear();
    void initReset();
    int get(int, int, void *);
    int get_ain(int, void *);
    void set(int, int, void *);
    void set_sys(int, void *);
    char get_din(int ch);
    char get_dout(int ch);
    void set_dout(int ch, char val);
    void output_en();
    char get_dbg_jmpr_get();
    char get_rst_jmpr_get();
    void retain(unsigned int offset, unsigned int count, void *p);
    void retain_remind(unsigned int offset, unsigned int count, void *p);
    int retain_check();
    void retain_validate();
    void retain_invalidate();
    void retain_reset();
    int retain_close();
    int modbus_cb_read(u16 start_addr, u16 word_count, u16 *data_words);
    int modbus_cb_write(u16 start_addr, u16 word_count, u16 *data_words);
    int setip(set_ip_t *);
    void load_config();
    void save_config();
    void reset_config();
    int start_tftpd();
    void eraseapp();
    void setAppProtect();
    void writeApp(const char *, int);

private:

};
extern hwboard board;
#include "ch423.h"
extern ch423 ch;

#include "Rtc_Pcf8563.h"
extern Rtc_Pcf8563 pcf8563;
#ifdef USE_USBH
#include "usbstick.h"
extern USBStick usb;
#endif
extern int test_index;
// extern FlashFs flash_fs;
extern "C"
{
    void plc_set_state(u8 state);
}

extern HardwareSerial *Serials[];
#endif
